package b2.widget.social
{
	import b2.config.*;
	import b2.net.*;
	import b2.player.*;
	import b2.widget.*;
	import b2.widget.friend.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.ui.*;

	public class SocialInfoItem extends Sprite
	{
		private var socialInfo:SocialInfo;
		
		public function SocialInfoItem(socialInfo:SocialInfo)
		{
			super();
			this.socialInfo = socialInfo;
			var tankConfig:TankConfig = Config.objectConfigs[socialInfo.attackerTankIndex];
			//背景框
			var RankingItemBgr:Class = ResourceHelper.getInstance().getClassByName("RankingItemBgr");
			var rankingItemBgr:Sprite = new RankingItemBgr();
			addChild(rankingItemBgr);
			//坦克背景框
			var ObjectItemBgr:Class = ResourceHelper.getInstance().getClassByName("ObjectItemBgr" + socialInfo.attackerTankBasicLevel);
			var objectItemBgr:Sprite = new ObjectItemBgr();
			objectItemBgr.x = 20;
			objectItemBgr.y = 9;
			objectItemBgr.width = 40;
			objectItemBgr.height = 40;
			addChild(objectItemBgr);
			//坦克图片
			var TankImage:Class = ResourceHelper.getInstance().getClassByName(tankConfig.iconImage);
			var tankSprite:Sprite = new TankImage();
			//齐天大圣
			if (tankConfig.index == 10015)
			{
				tankSprite.width = 48;
				tankSprite.height = 54;
			}
			//死亡骑士
			else if (tankConfig.index == 10020)
			{
				tankSprite.width = 42;
				tankSprite.height = 42;
			}
			else
			{
				tankSprite.width = 35;
				tankSprite.height = 35;
			}
			tankSprite.x = 22;
			tankSprite.y = 11;
			addChild(tankSprite);
			//攻击者
			var attackerText:TextField = new TextField();
			attackerText.selectable = false;
        	attackerText.autoSize = TextFieldAutoSize.LEFT;
        	attackerText.multiline = true;
			attackerText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			attackerText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			attackerText.x = 80;
			attackerText.y = 10;
			attackerText.htmlText = "<font color='#0000FF'>" + socialInfo.attackerName + "</font> 在 <font color='#0000FF'>" + 
				socialInfo.attackDate.substr(5, 11) + "</font> 攻击你的要塞。<br>抢走荣誉 <font color='#00AA00'>" + socialInfo.honourChange + "</font>";
			addChild(attackerText);
			//报复
			var ButtonFire:Class = ResourceHelper.getInstance().getClassByName("ButtonFire");
			var revengeButton:BasicButton = new BasicButton(ButtonFire, "<b><font color='#FF0000'>向 ta 复仇</font></b>");
			revengeButton.x = 310;
			revengeButton.y = 12;
			addChild(revengeButton);
			revengeButton.addEventListener(MouseEvent.CLICK, onMouseClick);
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			ServerHelper.getInstance().getPlayerInfo(socialInfo.attackerId);
			ServerHelper.getInstance().addEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
		}
		
		private function onShowTankInfoComplete(event:ServerEvent):void
		{
			ServerHelper.getInstance().removeEventListener(ServerEvent.GET_PLAYER_INFO, onShowTankInfoComplete);
			var friendDialog:FriendDialog = new FriendDialog(1, socialInfo.attackerId);
			WidgetManager.getInstance().popOut([friendDialog], true, true);
		}
		
	}
}